package com.innjia.sys.controller;

import java.util.List;
import java.util.Map;
import com.innjia.base.utils.ValidatorUtils;
import com.xiaoleilu.hutool.lang.Validator;
import org.apache.commons.lang3.StringUtils;
import org.apache.log4j.Logger;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import com.innjia.sys.entity.WishListEntity;
import com.innjia.sys.service.WishListService;
import com.innjia.base.utils.PageUtils;
import com.innjia.base.utils.Query;
import com.innjia.base.utils.Result;
import javax.servlet.http.HttpServletRequest;


/**
 * 
 * 
 * @author innjia
 * @email innjia@innjia.com
 * @date 2017-11-30 17:44:47
 */
@RestController
@RequestMapping("sys/wishlist")
public class WishListController extends BaseController{

    private Logger logger = Logger.getLogger(WishListController.class);
    @Autowired
	private WishListService wishListService;
	
	/**
	 * 分页条件查询心愿单列表
	 */
	@RequestMapping("/list")
	//@RequiresPermissions("wishlist:list")
	public Result list(HttpServletRequest request){

	    PageUtils pageUtil = new PageUtils();
		
		String wishStatus =  request.getParameter("wishStatus");
		String rentType =  request.getParameter("rentType");
		String phone =  request.getParameter("phone");
		String page =  request.getParameter("page");
		String limit =  request.getParameter("limit");
		if((!StringUtils.equals(wishStatus,"0")) && (!StringUtils.equals(wishStatus,"1"))){
            //return Result.error("心愿单状态错误");
            wishStatus = null;
        }
        if((!StringUtils.equals(rentType,"0")) && (!StringUtils.equals(rentType,"1"))){
            //return Result.error("出租状态错误");
            rentType = null;
        }
        try {
            int currPage = Integer.parseInt(page);
            pageUtil.setCurrPage(currPage < 1 ? 1 : currPage);
        } catch (NumberFormatException e) {
            pageUtil.setCurrPage(1);
        }
        try {
            int pageSize = Integer.parseInt(limit);
            pageUtil.setPageSize(pageSize < 1 ? 10 : pageSize);
        } catch (NumberFormatException e) {
            pageUtil.setPageSize(10);
        }

        WishListEntity wishlist = new WishListEntity();
		wishlist.setWishStatus(wishStatus);
		wishlist.setRentType(rentType);
		wishlist.setPhone(phone);

        List<WishListEntity> list = this.wishListService.queryPageListByBean(wishlist,pageUtil);

        pageUtil.setList(list);
        return Result.ok().put("page", pageUtil);
	}


	
	/**
	 * 信息
	 */
	@RequestMapping("/info/{id}")
	@RequiresPermissions("wishlist:info")
	public Result info(@PathVariable("id") String id){
		WishListEntity wishList = wishListService.queryObject(id);
		
		return Result.ok().put("wishList", wishList);
	}
	

	
	/**
	 * 修改
	 */
	@RequestMapping("/update")
	@RequiresPermissions("wishlist:update")
	public Result update(@RequestBody WishListEntity wishList){
		wishListService.update(wishList);
		
		return Result.ok();
	}
	
	/**
	 * 删除
	 */
	@RequestMapping("/delete")
	@RequiresPermissions("wishlist:delete")
	public Result delete(@RequestBody String[] ids){
		wishListService.deleteBatch(ids);
		
		return Result.ok();
	}
	
}
